<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<link rel="stylesheet" media="screen" href="css/docs.css" />
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<script type="text/javascript" src="${ctx }/datepicker/WdatePicker.js"></script>

<!-- jQplot SETUP END -->
<s:if test="#request.custom != null && #request.custom.id > 0">
	<h1 class="page-title">自定义薪资管理-方案修改</h1>
</s:if>
<s:else>
	<h1 class="page-title">自定义薪资管理-方案新增</h1>
</s:else>
<div class="container_12 clearfix leading">
	<form id="post_form" name="post_form">
		<s:if test="#request.custom != null && #request.custom.id > 0">
			<input type="hidden" name="custom.id" value="${custom.id}" />
		</s:if>
		<input type="hidden" name="custom.organization.id"
			value="${custom.organization.id}" />
		<div class="clear"></div>
		<h5>
			自定义薪资方案名称：<strong><input id="title" name="custom.projectTitle"
				type="text" style="width: 30%" value="${custom.projectTitle}"></strong>
		</h5>
		<div class="side">
			<h5>设定发放时间</h5>
			<div class="accordion">
				<header class="current">
					<h2 onclick="paymentTypeClick(this)">
						<input type="radio" name="custom.paymentType" value="0" <s:if test="#request.custom.id == null || #request.custom.id < 0">checked="checked"</s:if><s:if test="#request.custom.id > 0 && #request.custom.paymentType == 0">checked="checked"</s:if> /> 单次发放
					</h2>
				</header>
				<section class="clearfix" style="display: block;">
					<li class="required double" style="list-style-type: none">
						<div class="form-input">
							选择日期： <input id="singlePaymentDate" name="singlePaymentDate" onfocus="WdatePicker()" value='<s:date name="#request.custom.startDate" format="yyyy-MM-dd"/>'>
						</div>
					</li>
				</section>
				<header>
					<h2 onclick="paymentTypeClick(this)">
						<input type="radio" name="custom.paymentType" value="1" <s:if test="#request.custom.id > 0 && #request.custom.paymentType == 1">checked="checked"</s:if> /> 周期性发放时间
					</h2>
				</header>
				<section class="clearfix">
					<li class="required double" style="list-style-type: none">
						<table class="full">
							<tbody>
								<tr>
									<td><input name="custom.periodPayType" type="radio" value="monthly" <s:if test="#request.custom.periodPayType == null">checked="checked"</s:if><s:elseif test="#request.custom.periodPayType.toString().equals('monthly')">checked="checked"</s:elseif> />
										月度</td>
									<td><input name="custom.periodPayType" type="radio" value="bimonthly" <s:if test="#request.custom.periodPayType != null && #request.custom.periodPayType.toString().equals('bimonthly')">checked="checked"</s:if>/> 双月</td>
									<td><input name="custom.periodPayType" type="radio" value="season" <s:if test="#request.custom.periodPayType != null && #request.custom.periodPayType.toString().equals('season')">checked="checked"</s:if>/> 季度</td>
									<td><input name="custom.periodPayType" type="radio" value="semiyearly" <s:if test="#request.custom.periodPayType != null && #request.custom.periodPayType.toString().equals('semiyearly')">checked="checked"</s:if>/> 半年</td>
									<td><input name="custom.periodPayType" type="radio" value="annually" <s:if test="#request.custom.periodPayType != null && #request.custom.periodPayType.toString().equals('annually')">checked="checked"</s:if>/> 一年</td>
									<td class="ar" style="width: 25%">&nbsp;</td>
								</tr>
							</tbody>
						</table>
						<div class="form-input" style="margin-top: 20px">
							选择开始日期： <input id="startDate" name="startDate" onfocus="WdatePicker({maxDate:$('#endDate').val()})" value='<s:date name="#request.custom.startDate" format="yyyy-MM-dd"/>'>
							选择结束日期： <input id="endDate" name="endDate" onfocus="WdatePicker({minDate:$('#startDate').val()})" value='<s:date name="#request.custom.endDate" format="yyyy-MM-dd"/>'>
						</div>
					</li>
				</section>
			</div>
		</div>
		<div class="portlet leading">
			<header>
				<h6 style="margin-bottom: 0px">
					<a href="javascript:void(0)"><span
						style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>补贴部分</a>
				</h6>
			</header>
			<s:if test="(#request.custom.details != null && #request.subsidyItemLength > 0) || #request.custom.details == null || #request.custom.details.size() == 0">
				<section class="tabs side">
					<ul class="clearfix" style="width: 150px"
						id="insdetail_tabs_subsidy">
						<s:if
							test="#request.custom.details != null && #request.custom.details.size() > 0">
							<s:iterator var="dt" status="st"
								value="#request.custom.details">
								<s:if
									test="#dt.structType != null && #dt.structType.toString().equals('subsidy')">
									<li style="width: 150px"><a href="javascript:void(0)"
										onclick="tabChangeEvent(this,'subsidy')"><span
											style="background: url(${ctx}/images/img/add.png)"
											class="icon">&nbsp;</span><span>${dt.schemeTitle}</span></a></li>
								</s:if>
							</s:iterator>
						</s:if>
						<s:else>
							<li style="width: 150px"><a
								onclick="tabChangeEvent(this,'subsidy')"
								href="javascript:void(0)" class="current"><span class="icon"
									style="background: url(${ctx}/images/img/add.png)">&nbsp;</span><span></span></a></li>
						</s:else>
					</ul>
					<section style="margin-left: 150px" id="insdetail_sections_subsidy">
						<s:if
							test="#request.custom.details != null && #request.custom.details.size() > 0">
							<s:iterator var="dt" status="st"
								value="#request.custom.details">
								<s:if test="#dt.structType.toString().equals('subsidy')">
									<section class="clearfix"
										<s:if test="#st.index == 0">style="display:block"</s:if>
										<s:else>style="display:none"</s:else>>
										<h6>
											项目名称：<strong><input name="schemeTitle_subsidy"
												type="text" style="width: 30%" value="${dt.schemeTitle}"></strong>
										</h6>
										<div class="portlet leading">
											<header>
												<h6 style="margin-bottom: 0px">
													设定项目：<a href="javascript:void(0)"></a>
												</h6>
											</header>
	
											<section>
												<table class="display" id="example" style="clear: none">
													<thead>
														<tr>
															<th>挂钩数据</th>
															<th>细项</th>
															<th>单位</th>
															<th>每单位补贴</th>
															<th>固定补贴</th>
														</tr>
													</thead>
													<tbody>
														<tr class="gradeA">
															<td><select style="opacity: 0;"
																name="linkedDataType_subsidy"
																onchange="linkedSelectChangeEvent(this,'subsidy')">						
									<!-- 								<option value="no_link" <s:if test="#dt.linkedDataType.toString().equals('no_link')">selected="selected"</s:if>>无挂钩数据</option>
																	<option value="social_insurance" <s:if test="#dt.linkedDataType.toString().equals('social_insurance')">selected="selected"</s:if>>社保</option>
																	<option value="individual_tax" <s:if test="#dt.linkedDataType.toString().equals('individual_tax')">selected="selected"</s:if>>个人所得税</option>
																	<option value="overtime" <s:if test="#dt.linkedDataType.toString().equals('overtime')">selected="selected"</s:if>>加班费</option>
																	<option value="performance" <s:if test="#dt.linkedDataType.toString().equals('performance')">selected="selected"</s:if>>绩效奖金</option>
																	<option value="basic_salary" <s:if test="#dt.linkedDataType.toString().equals('basic_salary')">selected="selected"</s:if>>底薪</option> -->
																	<option value="erp_data" <s:if test="#dt.linkedDataType.toString().equals('erp_data')">selected="selected"</s:if>>ERP数据源</option>
																	<option value="examine" <s:if test="#dt.linkedDataType.toString().equals('examine')">selected="selected"</s:if>>考勤数据源</option>
															</select></td>
															<td><select name="linkedDataId_subsidy"
																style="opacity: 0;" onchange="linkedDataClick(this,'subsidy')">
																	<option value="-1">无细项</option>
																	<s:if test="#dt.linkedDataId > 0">
																		<option value="${dt.linkedDataId}" selected="selected">${dt.linkedDataTitle}</option>
																	</s:if>
															</select><input type="hidden" name="linkedDataTitle_subsidy" value="${dt.linkedDataTitle}"/></td>
															<td>次数</td>
															<td><strong> <input name="unitCost_subsidy"
																	type="text" style="width: 60px" value="${dt.unitCost}" />
																	元
															</strong></td>
															<td><input name="fixedCost_subsidy" type="text"
																style="width: 60px" value="${dt.fixedCost}" /> 元</td>
														</tr>
													</tbody>
												</table>
											</section>
										</div>
										<div class="tabs side grid_12 leading">
											<div class="clear"></div>
											<div class="grid_12">
												<div class="form-action clearfix">
													<p>
														<a name="modify" class="button" href="javascript:void(0)"
															onclick="modifyScheme(this,'subsidy')"><span
															style="background: url(${ctx}/images/img/page_edit.png)"
															class="icon">&nbsp;</span>修改</a> <a name="delete"
															class="button" href="javascript:void(0)"
															onclick="deleteScheme(this,'subsidy')"><span
															style="background: url(${ctx}/images/img/cancel.png)"
															class="icon">&nbsp;</span>删除</a>
													</p>
												</div>
											</div>
										</div>
									</section>
								</s:if>
							</s:iterator>
						</s:if>
						<s:else>
							<section class="clearfix">
								<h6>
									项目名称：<strong><input name="schemeTitle_subsidy"
										type="text" style="width: 30%" value=""></strong>
								</h6>
								<div class="portlet leading">
									<header>
										<h6 style="margin-bottom: 0px">
											设定项目：<a href="javascript:void(0)"></a>
										</h6>
									</header>
	
									<section>
										<table class="display" id="example" style="clear: none">
											<thead>
												<tr>
													<th>挂钩数据</th>
													<th>细项</th>
													<th>单位</th>
													<th>每单位补贴</th>
													<th>固定补贴</th>
												</tr>
											</thead>
											<tbody>
												<tr class="gradeA">
													<td><select style="opacity: 0;"
														name="linkedDataType_subsidy"
														onchange="linkedSelectChangeEvent(this,'subsidy')">
															<option value="no_link">无挂钩数据</option>
															<!-- <option value="social_insurance">社保</option>
															<option value="individual_tax">个人所得税</option>
															<option value="overtime">加班费</option>
															<option value="performance">绩效奖金</option>
															<option value="basic_salary">底薪</option> -->
															<option value="erp_data">ERP数据源</option>
															<option value="examine">考勤数据源</option>
													</select></td>
													<td><select name="linkedDataId_subsidy"
														style="opacity: 0;" onchange="linkedDataClick(this,'subsidy')">
															<option value="-1">无细项</option>
													</select><input type="hidden" name="linkedDataTitle_subsidy" value="无细项"/></td>
													<td>次数</td>
													<td><strong> <input name="unitCost_subsidy"
															type="text" style="width: 60px" value="" />
															元
													</strong></td>
													<td><input name="fixedCost_subsidy" type="text"
														style="width: 60px" value="" /> 元</td>
												</tr>
											</tbody>
										</table>
									</section>
								</div>
								<div class="tabs side grid_12 leading">
									<div class="clear"></div>
									<div class="grid_12">
										<div class="form-action clearfix">
											<p>
												<a name="modify" class="button" href="javascript:void(0)"
													onclick="modifyScheme(this,'subsidy')"><span
													style="background: url(${ctx}/images/img/page_edit.png)"
													class="icon">&nbsp;</span>提交</a> <a name="delete" class="button"
													href="javascript:void(0)"
													onclick="deleteScheme(this,'subsidy')"><span
													style="background: url(${ctx}/images/img/cancel.png)"
													class="icon">&nbsp;</span>删除</a>
											</p>
										</div>
									</div>
								</div>
							</section>
						</s:else>
					</section>
					<div class="clear"></div>
					<div class="container_12 clearfix leading"
						style="padding-left: 20px">
						<div class="form-action clearfix" style="margin-left: 115px">
							<p>
								<a class="button" href="javascript:void(0)"
									onclick="appendScheme('subsidy')"><span
									style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>添加项目</a>
							</p>
						</div>
					</div>
				</section>
			</s:if>
		</div>
		<div class="portlet leading">
			<header>
				<h6 style="margin-bottom: 0px">
					<a href="#" style="color: #F00"><span
						style="background: url(images/img/delete.png)" class="icon">&nbsp;</span>扣款部分</a>
				</h6>
			</header>
			<s:if test="(#request.custom.details != null && #request.detainItemLength > 0) || #request.custom.details == null || #request.custom.details.size() == 0">
				<section class="tabs side">
					<ul class="clearfix" style="width: 150px" id="insdetail_tabs_detain">
						<s:if
							test="#request.custom.details != null && #request.custom.details.size() > 0">
							<s:iterator var="dt" status="st"
								value="#request.custom.details">
								<s:if test="#dt.structType != null && #dt.structType.toString().equals('detain')">
									<li style="width: 150px"><a href="javascript:void(0)"
										onclick="tabChangeEvent(this,'detain')"><span
											style="background: url(${ctx}/images/img/delete.png)"
											class="icon">&nbsp;</span><span>${dt.schemeTitle}</span></a></li>
								</s:if>
							</s:iterator>
						</s:if>
						<s:else>
							<li style="width: 150px"><a
								onclick="tabChangeEvent(this,'detain')" href="javascript:void(0)"
								class="current"><span class="icon"
									style="background: url(${ctx}/images/img/delete.png)">&nbsp;</span><span></span></a></li>
						</s:else>
					</ul>
					<section style="margin-left: 150px" id="insdetail_sections_detain">
						<s:if
							test="#request.custom.details != null && #request.custom.details.size() > 0">
							<s:iterator var="dt" status="st"
								value="#request.custom.details">
								<s:if test="#dt.structType.toString().equals('detain')">
									<section class="clearfix"
										<s:if test="#st.index == 0">style="display:block"</s:if>
										<s:else>style="display:none"</s:else>>
										<h6>
											项目名称：<strong><input name="schemeTitle_detain"
												type="text" style="width: 30%" value="${dt.schemeTitle}"></strong>
										</h6>
										<div class="portlet leading">
											<header>
												<h6 style="margin-bottom: 0px">
													设定项目：<a href="javascript:void(0)"></a>
												</h6>
											</header>
	
											<section>
												<table class="display" id="example" style="clear: none">
													<thead>
														<tr>
															<th>挂钩数据</th>
															<th>细项</th>
															<th>单位</th>
															<th>每单位补贴</th>
															<th>固定补贴</th>
														</tr>
													</thead>
													<tbody>
														<tr class="gradeX">
															<td><select style="opacity: 0;"
																name="linkedDataType_detain"
																onchange="linkedSelectChangeEvent(this,'detain')">						
																	<option value="no_link" <s:if test="#dt.linkedDataType.toString().equals('no_link')">selected="selected"</s:if>>无挂钩数据</option>
																	<!-- <option value="social_insurance" <s:if test="#dt.linkedDataType.toString().equals('social_insurance')">selected="selected"</s:if>>社保</option>
																	<option value="individual_tax" <s:if test="#dt.linkedDataType.toString().equals('individual_tax')">selected="selected"</s:if>>个人所得税</option>
																	<option value="overtime" <s:if test="#dt.linkedDataType.toString().equals('overtime')">selected="selected"</s:if>>加班费</option>
																	<option value="performance" <s:if test="#dt.linkedDataType.toString().equals('performance')">selected="selected"</s:if>>绩效奖金</option>
																	<option value="basic_salary" <s:if test="#dt.linkedDataType.toString().equals('basic_salary')">selected="selected"</s:if>>底薪</option> -->
																	<option value="erp_data" <s:if test="#dt.linkedDataType.toString().equals('erp_data')">selected="selected"</s:if>>ERP数据源</option>
																	<option value="examine" <s:if test="#dt.linkedDataType.toString().equals('examine')">selected="selected"</s:if>>考勤数据源</option>
															</select></td>
															<td><select name="linkedDataId_detain"
																style="opacity: 0;" onchange="linkedDataClick(this,'detain')">
																	<option value="-1">无细项</option>
																	<s:if test="#dt.linkedDataId > 0">
																		<option value="${dt.linkedDataId}" selected="selected">${dt.linkedDataTitle}</option>
																	</s:if>
															</select><input type="hidden" name="linkedDataTitle_detain" value="${dt.linkedDataTitle}"/></td>
															<td>次数</td>
															<td><strong> <input name="unitCost_detain"
																	type="text" style="width: 60px" value="${dt.unitCost}" />
																	元
															</strong></td>
															<td><input name="fixedCost_detain" type="text"
																style="width: 60px" value="${dt.fixedCost}" /> 元</td>
														</tr>
													</tbody>
												</table>
											</section>
										</div>
										<div class="tabs side grid_12 leading">
											<div class="clear"></div>
											<div class="grid_12">
												<div class="form-action clearfix">
													<p>
														<a name="modify" class="button" href="javascript:void(0)"
															onclick="modifyScheme(this,'detain')"><span
															style="background: url(${ctx}/images/img/page_edit.png)"
															class="icon">&nbsp;</span>修改</a> <a name="delete"
															class="button" href="javascript:void(0)"
															onclick="deleteScheme(this,'detain')"><span
															style="background: url(${ctx}/images/img/cancel.png)"
															class="icon">&nbsp;</span>删除</a>
													</p>
												</div>
											</div>
										</div>
									</section>
								</s:if>
							</s:iterator>
						</s:if>
						<s:else>
							<section class="clearfix">
								<h6>
									项目名称：<strong><input name="schemeTitle_detain"
										type="text" style="width: 30%" value=""></strong>
								</h6>
								<div class="portlet leading">
									<header>
										<h6 style="margin-bottom: 0px">
											设定项目：<a href="javascript:void(0)"></a>
										</h6>
									</header>
	
									<section>
										<table class="display" id="example" style="clear: none">
											<thead>
												<tr>
													<th>挂钩数据</th>
													<th>细项</th>
													<th>单位</th>
													<th>每单位补贴</th>
													<th>固定补贴</th>
												</tr>
											</thead>
											<tbody>
												<tr class="gradeX">
													<td><select style="opacity: 0;"
														name="linkedDataType_detain"
														onchange="linkedSelectChangeEvent(this,'detain')">
															<option value="no_link">无挂钩数据</option>
															<!-- <option value="social_insurance">社保</option>
															<option value="individual_tax">个人所得税</option>
															<option value="overtime">加班费</option>
															<option value="performance">绩效奖金</option>
															<option value="basic_salary">底薪</option> -->
															<option value="erp_data">ERP数据源</option>
															<option value="examine">考勤数据源</option>
													</select></td>
													<td><select name="linkedDataId_detain"
														style="opacity: 0;" onchange="linkedDataClick(this,'detain')">
															<option value="-1">无细项</option>
													</select><input type="hidden" name="linkedDataTitle_detain" value="无细项"/></td>
													<td>次数</td>
													<td><strong> <input name="unitCost_detain"
															type="text" style="width: 60px" value="" />
															元
													</strong></td>
													<td><input name="fixedCost_detain" type="text"
														style="width: 60px" value="" /> 元</td>
												</tr>
											</tbody>
										</table>
									</section>
								</div>
								<div class="tabs side grid_12 leading">
									<div class="clear"></div>
									<div class="grid_12">
										<div class="form-action clearfix">
											<p>
												<a name="modify" class="button" href="javascript:void(0)"
													onclick="modifyScheme(this,'detain')"><span
													style="background: url(${ctx}/images/img/page_edit.png)"
													class="icon">&nbsp;</span>提交</a> <a name="delete" class="button"
													href="javascript:void(0)"
													onclick="deleteScheme(this,'detain')"><span
													style="background: url(${ctx}/images/img/cancel.png)"
													class="icon">&nbsp;</span>删除</a>
											</p>
										</div>
									</div>
								</div>
							</section>
						</s:else>
					</section>
					<div class="clear"></div>
					<div class="container_12 clearfix leading"
						style="padding-left: 20px">
						<div class="form-action clearfix" style="margin-left: 115px">
							<p>
								<a class="button" href="javascript:void(0)"
									onclick="appendScheme('detain')"><span
									style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>添加项目</a>
							</p>
						</div>
	
					</div>
	
				</section>
			</s:if>
		</div>
		<div class="clear"></div>
		<div class="tabs side grid_12 leading">

			<div class="clear"></div>
		</div>
	</form>
</div>

<div class="clear"></div>
<div class="container_12 clearfix leading" style="padding-left: 20px">


	<div class="form-action clearfix">
		<p>
			<a class="button" href="javascript:void(0)" onclick="checkForm()"><span
				style="background: url(${ctx}/images/img/page_edit.png)"
				class="icon">&nbsp;</span>确定提交</a> <a class="button"
				href="#salary/custom_main.xhtml?organizationId=${custom.organization.id}"><span
				style="background: url(${ctx}/images/img/arrow_undo.png)"
				class="icon">&nbsp;</span>返回</a>
		</p>
	</div>

</div>

<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript">
	/**
	 * 添加项目模块
	 */
	function appendScheme(mod) {
		//remove the current activity div
		$("#insdetail_tabs_" + mod).find("a").removeClass("current");
		$("#insdetail_sections_" + mod + ">section").attr("style",
				"display:none");
		var indexName = new Date().getTime();
		var tabHTML = "<li style=\"width: 150px\"><a class=\"current\" href=\"javascript:void(0)\" onclick=\"tabChangeEvent(this,'"
				+ mod
				+ "')\"><span style=\"background: url(${ctx}/images/img/" + (mod == "subsidy" ? "add" : "delete") + ".png)\" class=\"icon\">&nbsp;</span><span></span></a></li>";
		var sectionHTML = "<section class=\"clearfix\">";
		sectionHTML += "	<h6>";
		sectionHTML += "		项目名称：<strong><input name=\"schemeTitle_" + mod + "\" type=\"text\" style=\"width: 30%\" value=\"\"></strong>";
		sectionHTML += "	</h6>";
		sectionHTML += "	<div class=\"portlet leading\">";
		sectionHTML += "		<header>";
		sectionHTML += "			<h6 style=\"margin-bottom: 0px\">设定项目：<a href=\"javascript:void(0)\"></a></h6>";
		sectionHTML += "		</header>";
		sectionHTML += "		<section>";
		sectionHTML += "			<table class=\"display\" id=\"example\" style=\"clear: none\">";
		sectionHTML += "				<thead>";
		sectionHTML += "					<tr>";
		sectionHTML += "						<th>挂钩数据</th>";
		sectionHTML += "						<th>细项</th>";
		sectionHTML += "						<th>单位</th>";
		sectionHTML += "						<th>每单位补贴</th>";
		sectionHTML += "						<th>固定补贴</th>";
		sectionHTML += "					</tr>";
		sectionHTML += "				</thead>";
		sectionHTML += "				<tbody>";
		if(mod == "subsidy"){
			sectionHTML += "					<tr class=\"gradeA\">";
		}else{
			sectionHTML += "					<tr class=\"gradeX\">";
		}
		sectionHTML += "						<td>";
		sectionHTML +="							<select name=\"linkedDataType_" + mod + "\" onchange=\"linkedSelectChangeEvent(this,'" + mod + "')\">";
		sectionHTML += "							<option value=\"no_link\">无挂钩数据</option>";
		var optionArray = new Array();
		/* optionArray.push("<option value=\"social_insurance\">社保</option>");
		optionArray.push("<option value=\"individual_tax\">个人所得税</option>");
		optionArray.push("<option value=\"overtime\">加班费</option>");
		optionArray.push("<option value=\"performance\">绩效奖金</option>");
		optionArray.push("<option value=\"basic_salary\">底薪</option>"); */
		optionArray.push("<option value=\"erp_data\">ERP数据源</option>");
		optionArray.push("<option value=\"examine\">考勤数据源</option>");
		$("select[name='linkedDataType_" + mod + "']").each(function(i){
			for(var i=0;i<optionArray.length;i++){
				if(optionArray[i].indexOf(this.value) >= 0 && (this.value == "social_insurance" || this.value == "individual_tax" 
						|| this.value == "overtime" || this.value == "performance" || this.value == "basic_salary")){
					optionArray.splice(i,1);
				}
			}
		});
		for(var i=0;i<optionArray.length;i++){
			sectionHTML += optionArray[i];
		}
		sectionHTML += "						</select></td>";
		sectionHTML += "						<td><select name=\"linkedDataId_" + mod + "\" onchange=\"linkedDataClick(this,'" + mod + "')\">";
		sectionHTML += "							<option value=\"-1\">无细项</option>";
		sectionHTML += "						</select><input type=\"hidden\" name=\"linkedDataTitle_" + mod + "\" value=\"无细项\"/></td>";
		sectionHTML += "						<td>次数</td>";
		sectionHTML += "						<td><strong> <input name=\"unitCost_" + mod + "\" type=\"text\" style=\"width: 60px\" value=\"\" />元</strong></td>";
		sectionHTML += "						<td><input name=\"fixedCost_" + mod + "\" type=\"text\" style=\"width: 60px\" value=\"\" /> 元</td>";
		sectionHTML += "					</tr>";
		sectionHTML += "				</tbody>";
		sectionHTML += "			</table>";
		sectionHTML += "		</section>";
		sectionHTML += "	</div>";
		sectionHTML += "	<div class=\"tabs side grid_12 leading\">";
		sectionHTML += "		<div class=\"clear\"></div>";
		sectionHTML += "		<div class=\"grid_12\">";
		sectionHTML += "			<div class=\"form-action clearfix\">";
		sectionHTML += "				<p>";
		sectionHTML += "					<a name=\"modify\" class=\"button\" href=\"javascript:void(0)\"";
		sectionHTML += "						onclick=\"modifyScheme(this,'" + mod + "')\"><span";
		sectionHTML += "						style=\"background: url(${ctx}/images/img/page_edit.png)\"";
		sectionHTML += "						class=\"icon\">&nbsp;</span>提交</a> <a name=\"delete\" class=\"button\"";
		sectionHTML += "						href=\"javascript:void(0)\"";
		sectionHTML += "						onclick=\"deleteScheme(this,'" + mod + "')\"><span";
		sectionHTML += "						style=\"background: url(${ctx}/images/img/cancel.png)\"";
		sectionHTML += "						class=\"icon\">&nbsp;</span>删除</a>";
		sectionHTML += "				</p>";
		sectionHTML += "			</div>";
		sectionHTML += "		</div>";
		sectionHTML += "	</div>";
		sectionHTML += "</section>";
		
		$("#insdetail_tabs_" + mod).append(tabHTML);
		$("#insdetail_sections_" + mod).append(sectionHTML);
	}

	/**
	 * ul li item to click.
	 */
	function tabChangeEvent(clkObj, mod) {
		var ci = 0;
		$("#insdetail_tabs_" + mod).find("a").removeClass("current");
		$("#insdetail_sections_" + mod + ">section").attr("style",
				"display:none");
		$("#insdetail_tabs_" + mod).find("a").each(function(i) {
			if (this == clkObj) {
				$(this).addClass("current");
				ci = i;
			}
		});
		$("#insdetail_sections_" + mod + ">section").each(function(i) {
			if (ci == i) {
				$(this).attr("style", "display:block");
			}
		});
	}

	function focusTabCallBack(ci, mod) {
		$("#insdetail_tabs_" + mod).find("a").removeClass("current");
		$("#insdetail_sections_" + mod + ">section").attr("style",
				"display:none");
		$("#insdetail_tabs_" + mod).find("a").each(function(i) {
			if (ci == i) {
				$(this).addClass("current");
			}
		});
		$("#insdetail_sections_" + mod + ">section").each(function(i) {
			if (ci == i) {
				$(this).attr("style", "display:block");
			}
		});
	}

	/**
	 *	段落确定修改
	 */
	function modifyScheme(clkObj, mod) {
		var ci = 0;
		var mvalue = "";
		$("#insdetail_sections_" + mod).find("a[name='modify']").each(
				function(i) {
					if (this == clkObj) {
						ci = i;
					}
				});
		$("#insdetail_sections_" + mod + ">section")
				.each(
						function(i) {
							if (ci == i) {
								mvalue = $(this).find(
										"input[name='schemeTitle_" + mod
												+ "']").val();
							}
						});
		$("#insdetail_tabs_" + mod).find("a").each(function(i) {
			if (ci == i) {
				$(this).find("span:last").html(mvalue);
			}
		});
		if(mvalue != ""){
			$(clkObj).html("<span class=\"icon\" style=\"background: url(${ctx}/images/img/page_edit.png)\">&nbsp;</span>修改");
		}
	}

	/**
	 * 删除段落
	 */
	function deleteScheme(clkObj, mod) {
		if (confirm("确定要删除吗？")) {
			var ci = 0;
			$("#insdetail_sections_" + mod).find("a[name='delete']").each(
					function(i) {
						if (this == clkObj) {
							ci = i;
						}
					});
			$("#insdetail_sections_" + mod + ">section").each(function(i) {
				if (ci == i) {
					$(this).remove();
				}
			});
			$("#insdetail_tabs_" + mod).find("li").each(function(i) {
				if (ci == i) {
					$(this).remove();
				}
			});
			$("#insdetail_sections_" + mod + ">section:last").attr("style",
					"display:block");
			$("#insdetail_tabs_" + mod + " a:last").addClass("current");
		}
	}
	
	/**
	 * 挂勾数据修改
	 */
	function linkedSelectChangeEvent(obj,mod){
        var linkedDataIdObj = $(obj).parent().parent().parent().find("select[name='linkedDataId_" + mod + "']");
        $(linkedDataIdObj).find("option").remove();
		$.ajax({
	        type:"get",
	        url:"/ajax/salary_linkeddata_list.xhtml?organizationId=${custom.organization.id}&linkedDataType=" + obj.value,
	        //data: "name=John&location=Boston",
	        dataType:"json",
	        success:function (data) {
	    		var strLinkedDataHTML = "<option value=\"-1\">无细项</option>";
        		 if (data != null && data.length > 0) {
                     $.each(data, function (i, linked) {
                    	 strLinkedDataHTML += "<option value=\"" + linked.id + "\">" + linked.title + "</option>";
                     });
        		 }
                 $(linkedDataIdObj).append(strLinkedDataHTML);
	        }
	    });
		
		var linkedDataTitleObj = $(obj).parent().parent().parent().find("input[name='linkedDataTitle_" + mod + "']");
		$(linkedDataTitleObj).val("无细项");
	}
	
	function linkedDataClick(obj,mod){
		var linkedDataTitleObj = $(obj).parent().parent().parent().find("input[name='linkedDataTitle_" + mod + "']");
		var selectTitle = $(obj).parent().parent().parent().find("select[name='linkedDataId_" + mod+"']").find("option:selected").text();
		$(linkedDataTitleObj).val(selectTitle);
	}
	
	function paymentTypeClick(obj){
		$("input[name='custom.paymentType']").removeAttr("checked");
		$(obj).find("input[name='custom.paymentType']").attr("checked","checked");
	}

	function checkForm() {
		if (checkNull($("#title").attr("value"))) {
			alert("方案名称不能空");
			$("#title").focus();
			return false;
		}
		
		var paytype = $('input[name="custom.paymentType"][checked]').val();
		if(paytype == 0){
			if (checkNull($("#singlePaymentDate").attr("value"))) {
				alert("发放时间不能空");
				$("#singlePaymentDate").focus();
				return false;
			}
		}else{
			if (checkNull($("#startDate").attr("value"))) {
				alert("发放开始时间不能空");
				$("#startDate").focus();
				return false;
			}
			if (checkNull($("#endDate").attr("value"))) {
				alert("发放结束时间不能空");
				$("#endDate").focus();
				return false;
			}
		}
		
		var checkScheme = true;
		//检测补贴项目组 
		$("input[name='schemeTitle_subsidy']").each(function(i) {
			if (checkNull($(this).val())) {
				alert("补贴部分项目名称不能为空");
				$(this).focus();
				focusTabCallBack(i, "subsidy");
				checkScheme = false;
			}
		});
		if (!checkScheme) {
			return false;
		}
		$("input[name='unitCost_subsidy']").each(function(i) {
			if (isNaN($(this).val())) {
				alert("每单位补贴只能为数字");
				$(this).val("");
				$(this).focus();
				focusTabCallBack(i, "subsidy");
				checkScheme = false;
			}
		});
		if (!checkScheme) {
			return false;
		}
		$("input[name='fixedCost_subsidy']").each(function(i) {
			if (isNaN($(this).val())) {
				alert("固定补贴只能为数字");
				$(this).val("");
				$(this).focus();
				focusTabCallBack(i, "subsidy");
				checkScheme = false;
			}
		});
		if (!checkScheme) {
			return false;
		}
		//检测补贴项目组结束 
		$("input[name='schemeTitle_detain']").each(function(i) {
			if (checkNull($(this).val())) {
				alert("扣款部分项目名称不能为空");
				$(this).focus();
				focusTabCallBack(i, "detain");
				checkScheme = false;
			}
		});
		if (!checkScheme) {
			return false;
		}
		
		$("input[name='unitCost_detain']").each(function(i) {
			if (isNaN($(this).val())) {
				alert("每单位扣款只能为数字");
				$(this).val("");
				$(this).focus();
				focusTabCallBack(i, "detain");
				checkScheme = false;
			}
		});
		if (!checkScheme) {
			return false;
		}
		$("input[name='fixedCost_detain']").each(function(i) {
			if (isNaN($(this).val())) {
				alert("固定扣款只能为数字");
				$(this).val("");
				$(this).focus();
				focusTabCallBack(i, "detain");
				checkScheme = false;
			}
		});
		if (!checkScheme) {
			return false;
		}

		//提交数据 
		var url = "${ctx}/salary/post_custom.xhtml";
		$
				.ajax(
						url,
						{
							type : "POST",
							data : $("#post_form").serialize(),
							dataType : "html",
							cache : false,
							success : function(a) {
								alert("提交成功");
								window.location.href = "${ctx}/index.xhtml#salary/custom_main.xhtml?organizationId=${custom.organization.id}";
							},
							error : function(XMLHttpRequest, textStatus,
									errorThrown) {
								alert('提交申请发生异常');
							},
							complete : function() {
							}
						});
	}

	
</script>